home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / tcp / GUI_Archie097c.lha / GUI-Archie0.97c / GUI-Archie next >
Text File  |  1995-04-16  |  12KB  |  447 lines

  1. /*rx*/
  2. /*
  3.  * $VER: GUI-Archie 0.97ß (20/03/95)
  4.  *
  5.  * Problems? Email: phil@curve.demon.co.uk
  6.  *
  7.  * Requirements: ARexx running, RexxReqTools installed, Archie 38.1
  8.  *               FTPGet, an AmigaGuide viewer.
  9.  *
  10.  * Usage: GUI-Archie [HIRES=HR]
  11.  *
  12.  * Use the HIRES switch if you are running a HiRes Workbench (it'll
  13.  * make the buttons fit, that's all)
  14.  *
  15.  * ToDo: change localdir
  16.  *
  17.  *
  18.  *
  19. */
  20.  
  21.                    /**************************************/
  22. /******************** Change these defaults, if you want *******************/
  23.                    /**************************************/
  24.  
  25. HOSTNAME = 'archie.doc.ic.ac.uk'           /* default Archie host          */
  26. CLIENTNAME = 'inet:bin/archie'             /* path of Archie client        */
  27. VIEWER = 'dh0:utilities/multiview'         /* path of AmigaGuide viewer    */
  28. FTP_CMD = 'inet:bin/ftpget'                /* path of FTPGet command       */
  29.  
  30. MAXHITS = '30'                             /* default maximum hits value   */
  31.  
  32.                            /********************/
  33. /**************************** Leave the rest!! *****************************/
  34.                            /******(please)******/
  35.  
  36. /* var setup */
  37.  
  38. parse arg arguments
  39. if (find(upper(arguments), "HIRES")=1)|(find(upper(arguments), "HR")=1) then HIRES = 1
  40. if HIRES ~=1 then HIRES = 0
  41. if (find(upper(arguments), "?")=1)|(find(upper(arguments), "-?")=1) then HELP = 1
  42.  
  43. if exists("libs:rexxreqtools.library")>0 then do
  44.    addlib('rexxreqtools.library',0,-30)
  45. end
  46. if (exists("libs:rexxreqtools.library")=0) then do
  47.    say 'RexxReqTools is not installed! Install it and try again.'
  48.    exit
  49. end
  50.  
  51. if HELP = 1 then call proc_help()
  52.  
  53. VIEWER_PATH = 'dh0:utilities/'
  54.  
  55. TEMPIN = "t:gui-archie_in.tmp"
  56. TEMPOUT = "t:gui-archie_out.tmp"
  57. TEMPFLOW = "t:gui-archie_overflow.tmp"
  58. TEMPREAD = "t:GUI-Archie_Textfile.tmp"
  59. DIRLIST = "t:gui-archie_dirlist.tmp"
  60. CHECKFILE = "t:gui-archie_check.tmp"
  61. RXGET = "t:gui-archie_get.rexx"
  62.  
  63. SEARCHSTRING = ''
  64. SEARCHSTRING_ARG = 'Not Defined'
  65.  
  66. ARCHIE_VER = 'Archie 38.1'
  67. PROGNAME = 'GUI-Archie 0.97ß'
  68. TAGS = 'rt_reqpos=reqpos_centerwin'
  69.  
  70. signal on syntax
  71. signal on break_c
  72.  
  73. address command 'assign exists inet: >' CHECKFILE
  74. CHECK = open('checkami',CHECKFILE, read)
  75. CHECKASS = readln('checkami')
  76. CHECKAMI = left(CHECKASS, 5)
  77. CHECK = close('checkami')
  78. address command 'delete >NIL:' CHECKFILE
  79. if (CHECKAMI = 'inet:') then do
  80.    call rtezrequest('AmiTCP/IP version 2 or later must be started first.','_Exit' PROGNAME,PROGNAME,TAGS,)
  81.    exit
  82. end
  83.  
  84. /* check exist */
  85. call exister(CLIENTNAME)
  86. call exister(VIEWER)
  87. call exister(FTP_CMD)
  88.  
  89. NL = '0A'x
  90.  
  91. CASE_STAT = '_Case Insensitive'
  92. MATCH_STAT = '_Match SubString'
  93.  
  94. CASE_ARG = '-s'
  95. EXACT_ARG = ''
  96. MAXHITS_ARG = '-m' MAXHITS
  97.  
  98. say PROGNAME
  99. address command CLIENTNAME '-v'
  100.  
  101. /* main program */
  102.  
  103. proc_main:
  104.  
  105. do while MAIN_ANS ~= 0
  106.    call update_main()
  107.    call rtezrequest(MAIN_STATUS,'_Begin Search|_Enter Search String|_Change Host|_Options|E_xit',PROGNAME,TAGS,MAIN_ANS)
  108.    if MAIN_ANS = 0 then call proc_end()
  109.    if MAIN_ANS = 1 then call begin_search()
  110.    if MAIN_ANS = 2 then call enter_string()
  111.    if MAIN_ANS = 3 then call change_host()
  112.    if MAIN_ANS = 4 then call options()
  113.    drop MAIN_ANS
  114. end
  115.  
  116. call proc_end()
  117.  
  118. exit
  119.  
  120. /* logical prog end */
  121.  
  122. /* search proc */
  123.  
  124. begin_search:
  125.  
  126. if SEARCHSTRING = "" then do
  127.    NOSEARCH = rtezrequest('No search string defined','_Define One Then!|_Cancel Search',PROGNAME,TAGS,,)
  128.    if NOSEARCH = 1 then
  129.       call enter_string()
  130.    else
  131.       return
  132. end
  133. if SEARCHSTRING = "" then return
  134.  
  135. trace off
  136. say 'Archie searching.  Please wait...'
  137. address command CLIENTNAME '-o' TEMPIN  '-l -t -h' HOSTNAME CASE_ARG EXACT_ARG MAXHITS_ARG SEARCHSTRING
  138. call archie_err()
  139.  
  140. call proc_get()
  141. return
  142.  
  143. /* enter string proc */
  144.  
  145. enter_string:
  146.  
  147. OLDSEARCH = SEARCHSTRING
  148. NEWSEARCH = rtgetstring(SEARCHSTRING,'Enter string to search for..',PROGNAME,'_OK|_Cancel',TAGS,)
  149.  
  150. if NEWSEARCH = "" then do
  151.    SEARCHSTRING = OLDSEARCH
  152.    return
  153. end
  154. SEARCHSTRING = NEWSEARCH
  155. SEARCHSTRING_ARG = SEARCHSTRING
  156. return
  157.  
  158. /* change host proc */
  159.  
  160. change_host:
  161.  
  162. OLDHOST = HOSTNAME
  163. NEWHOST = rtgetstring(HOSTNAME,'Enter a new hostname..',PROGNAME,'_Accept|_Cancel',TAGS,)
  164.  
  165. if NEWHOST = "" then do
  166.    HOSTNAME = OLDHOST
  167.    return
  168. end
  169. HOSTNAME = NEWHOST
  170. return
  171.  
  172. /* options proc */
  173.  
  174. options:
  175.  
  176. do while OPT_ANS ~= 0
  177.    if HIRES = 1 then
  178.       MAXRES = 'Max'
  179.    else
  180.       MAXRES = 'Alter Maximum'
  181.    call rtezrequest('Click on an option to change it..',CASE_STAT'|'MATCH_STAT'|'MAXRES '_Hits ('MAXHITS')|Change _Viewer|_OK',PROGNAME,TAGS 'rtez_defaultresponse = 0',OPT_ANS)
  182.    if OPT_ANS = 0 then do
  183.       drop OPT_ANS
  184.       return
  185.    end
  186.    if OPT_ANS = 1 then do
  187.       if EXACT_ARG = '' then do
  188.          if CASE_ARG = '-s' then do
  189.             NEWCASE_STAT = '_Case Sensitive'
  190.             NEWCASE_ARG = '-c'
  191.          end
  192.          if CASE_ARG = '-c' then do
  193.             NEWCASE_STAT = '_Case Insensitive'
  194.             NEWCASE_ARG = '-s'
  195.          end
  196.          CASE_STAT = NEWCASE_STAT
  197.          CASE_ARG = NEWCASE_ARG
  198.       end
  199.    end
  200.    if OPT_ANS = 2 then do
  201.       if EXACT_ARG = '' then do
  202.          NEWMATCH_STAT = '_Match Exact Word'
  203.          NEWEXACT_ARG = '-e'
  204.          CASE_STAT = 'Case Sensitive'
  205.          CASE_ARG = '-c'
  206.       end
  207.       if EXACT_ARG = '-e' then do
  208.          NEWMATCH_STAT = '_Match SubString'
  209.          NEWEXACT_ARG = ''
  210.          CASE_STAT = '_Case Insensitive'
  211.          CASE_ARG = '-s'
  212.       end
  213.       MATCH_STAT = NEWMATCH_STAT
  214.       EXACT_ARG = NEWEXACT_ARG
  215.    end
  216.    if OPT_ANS = 3 then do
  217.       OLDMAXHITS = MAXHITS
  218.       NEWMAXHITS = rtgetlong(MAXHITS,'Enter new ''maximum hits'' value..',PROGNAME,'_Accept|_Cancel',TAGS,)
  219.       if NEWMAXHITS = "" then
  220.          MAXHITS = OLDMAXHITS
  221.       else
  222.          MAXHITS = NEWMAXHITS
  223.       MAXHITS_ARG = '-m' MAXHITS
  224.    end
  225.    if OPT_ANS = 4 then do
  226.       OLDVIEWER = VIEWER
  227.       NEWVIEWER = rtfilerequest(VIEWER_PATH,,'Choose an AmigaGuide viewer..',,TAGS 'rtfi_height=300',,)
  228.       if NEWVIEWER = "" then
  229.          VIEWER = OLDVIEWER
  230.       else
  231.          VIEWER = NEWVIEWER
  232.    end
  233.    drop OPT_ANS
  234. end
  235. return
  236.  
  237. /* main window update */
  238.  
  239. update_main:
  240.  
  241. if CASE_ARG = '-s' then MAINCASE_STAT = 'Insensitive'
  242. if CASE_ARG = '-c' then MAINCASE_STAT = 'Sensitive'
  243. if EXACT_ARG = '' then MAINEXACT_STAT = 'SubString'
  244. if EXACT_ARG = '-e' then MAINEXACT_STAT = 'Exact Word'
  245.  
  246. MAIN_STATUS = ARCHIE_VER NL NL'Current SearchString:  ' SEARCHSTRING_ARG NL'Host:  ' HOSTNAME NL'Match' MAINEXACT_STAT NL'Case' MAINCASE_STAT NL'Maximum Hits:  ' MAXHITS NL'Viewer:  ' VIEWER
  247. return
  248.  
  249. /** convert output **/
  250.  
  251. /* main conversion proc */
  252.  
  253. proc_get:
  254.  
  255. address command 'echo NOLINE "Post-processing..."'
  256.  
  257. INOP = open('in',TEMPIN, read)
  258. OUTOP = open('out',TEMPOUT, write)
  259. FLOWOP = open('overflow',TEMPFLOW,write)
  260. DIROP = open('dirlist',DIRLIST,write)
  261. RXGETOP = open('rxget',RXGET,write)
  262.  
  263. COUNT = 0
  264. LCOUNT = 0
  265. DCOUNT = 0
  266.  
  267. SETUP_LINE = writeln('out','@database GUI-Archie'NL'@node main'NL'@title "GUI-Archie Output (Click & Get Page)"'NL NL' @{b}Click on a file @{"·" LINK main} to retrieve it@{ub}'NL' @{b}Click on a ASCII file @{"+" LINK main} to read it@{ub}'NL)
  268. SETUP_FLOW = writeln('overflow','@database GUI-Archie Overflow'NL'@node main'NL'@title "GUI-Archie Output (Long lines)"'NL NL' @{b}@{u}Matches too long for click & get interface@{ub}@{uu}'NL)
  269. SETUP_DIR = writeln('dirlist','@database GUI-Archie Directories'NL'@node main'NL'@title "GUI-Archie Output (Directories)"'NL NL' @{b}@{u}Directories Matched@{ub}@{uu}'NL)
  270.  
  271. SETUP_RXGET = writeln('rxget','/*rx*/'NL'parse arg arguments'NL'trace off'NL'NL=''0A''x'NL'S=word(arguments,1)'NL'F=word(arguments,2)'NL'R=word(arguments,3)'NL'say ''Attempting FTP connection to'' S''...'''NL'if R~=''R'' then do')
  272. SETUP_RXGET2 = writeln('rxget','address command '''FTP_CMD''' S F 'NL'call e'NL'exit'NL'end'NL'if R=''R'' then do'NL'address command '''FTP_CMD''' S F ''local' TEMPREAD''''NL'call e'NL'end')
  273. SETUP_RXGETR = writeln('rxget','address command '''VIEWER TEMPREAD''''NL'exit')
  274. SETUP_RXGETE = writeln('rxget','e:'NL'if RC=0 then say ''Transfer successful'''NL'if RC=21 then say ''General error - email phil@curve.demon.co.uk with details.''')
  275. SETUP_RXGETE1 = writeln('rxget','if RC=22 then say ''Password argument unacceptable - email phil@curve.demon.co.uk with details.'''NL'if RC=23 then say ''Could not open bsdsocket.library''')
  276. SETUP_RXGETE2 = writeln('rxget','if RC=24 then say ''Remote site does not exist or cannot be resolved.'''NL'if RC=25 then say ''Remote server not responding.'''NL'if RC>25 then do'NL'if RC<29 then do'NL'say ''Anonymous login invalid.'''NL'end'NL'end')
  277. SETUP_RXGETE3 = writeln('rxget','if RC=29 then say ''The remote file no longer exists!'''NL'if RC=30 then say ''The local file cannot be written.'''NL'if RC=31 then say ''User aborted transfer.'''NL'if RC>0 then exit'NL'return')
  278. RXGETCLOSE = close('rxget')
  279.  
  280. do while eof('in')=0
  281.    INLINE = readln('in')
  282.    if COUNT = 0 then do
  283.       if INLINE = "" then do
  284.          call rtezrequest('No matches/Connection Error','_Huh!',PROGNAME,TAGS,)
  285.          INCLOSE = close('in')
  286.          OUTCLOSE = close('out')
  287.          FLOWCLOSE = close('overflow')
  288.          DIRCLOSE = close('dirlist')
  289.          say 'done.'
  290.          address command 'delete >NIL:' TEMPIN TEMPOUT TEMPFLOW DIRLIST TEMPREAD
  291.          return
  292.       end
  293.    end
  294.    if INLINE ~= "" then do
  295.       call proc_line()
  296.       if OUTLINE = LONG then do
  297.          LCOUNT = LCOUNT + 1
  298.          OUTFLOW = writeln('overflow',OVERFLOW)
  299.       end
  300.       if OUTLINE = DIR then do
  301.          DCOUNT = DCOUNT + 1
  302.          OUTDIR = writeln('dirlist',DIRECT)
  303.       end
  304.       if OUTLINE ~= LONG & OUTLINE ~= DIR then do
  305.          OUTWRITE = writeln('out',OUTLINE)
  306.       end
  307.    end
  308.    COUNT = COUNT + 1
  309. end
  310.  
  311. if DCOUNT >0 then do
  312.    writeln('out',NL' @{" Directories -' DCOUNT '" LINK' DIRLIST'/main}')
  313. end
  314.  
  315. if LCOUNT >0 then do
  316.    writeln('out',NL' @{" Long lines -' LCOUNT '" LINK' TEMPFLOW'/main}')
  317. end
  318.  
  319. SETDOWN_LINE = writeln('out','@endnode')
  320. SETFLOW_LINE = writeln('overflow',NL NL' @{" Back to ''Click & Get'' Page " LINK' TEMPOUT'/main}'NL'@endnode')
  321. SETDIR_LINE = writeln('dirlist',NL NL' @{" Back to ''Click & Get'' Page " LINK' TEMPOUT'/main}'NL'@endnode')
  322.  
  323. INCLOSE = close('in')
  324. OUTCLOSE = close('out')
  325. FLOWCLOSE = close('overflow')
  326. DIRCLOSE = close('dirlist')
  327.  
  328. say 'done.'
  329.  
  330. trace off
  331. address command VIEWER TEMPOUT
  332. call viewer_err()
  333.  
  334. address command "delete >NIL:" TEMPIN TEMPOUT TEMPFLOW DIRLIST RXGET
  335.  
  336. return
  337.  
  338. /* single line proc engine */
  339.  
  340. proc_line:
  341.  
  342. DATE = (left(INLINE,8))
  343. TIME = (substr(word(INLINE, 1),9,6))
  344.  
  345. YEAR = (substr(DATE,3,2))
  346. MONTH = (substr(DATE,5,2))
  347. DAY = (right(DATE,2))
  348.  
  349. HOUR = (left(TIME,2))
  350. MINS = (substr(TIME,2,2))
  351. SECS = (right(TIME,2))
  352.  
  353. BSIZE = (word(INLINE,2))
  354.  
  355. numeric digits 4
  356. SIZE = BSIZE / 1000
  357.  
  358. SITE = (word(INLINE,3))
  359.  
  360. FILE = (word(INLINE,4))
  361.  
  362. if (upper(right(FILE, 7))= ".README") then READ = 1
  363. if (upper(right(FILE, 4))= ".TXT") then READ = 1
  364. if (upper(right(FILE, 4))= ".DOC") then READ = 1
  365. if (upper(right(FILE, 4))= ".REA") then READ = 1
  366. if READ ~= 1 then READ = 0
  367.  
  368. if READ = 0 then do
  369.    OUTLINE = '@{b}'DAY'/'MONTH'/'YEAR '@{ub}@{"· 'SITE':'FILE'" RX "'RXGET SITE FILE'"} @{b}'SIZE'k@{ub}'
  370. end
  371.  
  372. if READ = 1 then do
  373.    OUTLINE = '@{b}'DAY'/'MONTH'/'YEAR '@{ub}@{"+ 'SITE':'FILE'" RX "'RXGET SITE FILE R'"} @{b}'SIZE'k@{ub}'
  374. end
  375.  
  376. drop READ
  377.  
  378. if right(FILE,1) = "/" then do
  379.    DIRECT = '@{b}'DAY'/'MONTH'/'YEAR '@{ub}'SITE':'FILE
  380.    OUTLINE = DIR
  381. end
  382.  
  383. if length(OUTLINE) >256 then do
  384.    OVERFLOW = SITE':'FILE '@{b}'SIZE'k ('DAY'/'MONTH'/'YEAR')@{ub}'
  385.    OUTLINE = LONG
  386. end
  387.  
  388. return
  389.  
  390. /* existential checks, man */
  391.  
  392. exister:
  393. arg CMD
  394.  
  395. if exists(CMD)=0 then do
  396.    say CMD 'not found.'
  397.    say 'Exiting.'
  398.    call proc_end()
  399. end
  400. return
  401.  
  402. /* break/error handling routines */
  403.  
  404. archie_err:
  405.  
  406. if RC = 20 then
  407.    say 'Archie abort.'
  408. else
  409.    say 'Archie returned.'
  410. trace normal
  411. drop RC
  412. return
  413.  
  414. viewer_err:
  415.  
  416. if RC = 20 then do
  417.    say 'Viewer error - check viewer can handle AmigaGuide files.'
  418. end
  419. trace normal
  420. return
  421.  
  422. BREAK_C:
  423.  
  424. say 'Ctrl-C detected. Aborting..'
  425. return
  426.  
  427. SYNTAX:
  428.  
  429. say 'General error.'
  430. return
  431.  
  432. /** end / delete proc **/
  433.  
  434. proc_end:
  435.  
  436. address command 'delete >NIL:' TEMPIN TEMPOUT TEMPFLOW DIRLIST RXGET TEMPREAD
  437. say PROGNAME 'out.'
  438. exit
  439.  
  440. /** usage **/
  441.  
  442. proc_help:
  443.  
  444. say 'Usage: GUI-Archie [HIRES=HR]'
  445. say 'Use the HIRES switch if you are running a HiRes Workbench.'
  446. exit
  447.